/*
  In App.xaml:
  <Application.Resources>
      <vm:ViewModelLocator xmlns:vm="clr-namespace:MuddyBoots.GreenlightQC.Mobile.UI"
                           x:Key="Locator" />
  </Application.Resources>
  
  In the View:
  DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"

  You can also use Blend to do all this with the tool's support.
  See http://www.galasoft.ch/mvvm
*/

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Ioc;
using Microsoft.Practices.ServiceLocation;

namespace MuddyBoots.GreenlightQC.Mobile.UI.ViewModel
{
    /// <summary>
    /// This class contains static references to all the view models in the
    /// application and provides an entry point for the bindings.
    /// </summary>
    public sealed class ViewModelLocator
    {
        static BootStrapper bootStrapper;
        /// <summary>
        /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
        public ViewModelLocator()
        {
            bootStrapper = new BootStrapper();
        }

        public static MainWindowViewModel Main
        {
            get
            {
                if (bootStrapper == null)
                {
                    bootStrapper = new BootStrapper();
                }

                return bootStrapper.Get<MainWindowViewModel>();
            }
        }

        public MainWindowViewModel MainWindowViewModel
        {
            get
            {
                return Main;
            }
        }
        
        public static void Cleanup()
        {
            if (bootStrapper == null)
            {
                return;
            }

            bootStrapper.Dispose();
            bootStrapper = null;
        }
    }
}